<?php
/**
 * Created by PhpStorm.
 * User: Qiangguo
 * Date: 14-9-11
 * Time: 上午10:00
 */
namespace Home\Controller;
use Think\Controller;
class AssignController extends Controller {
    public function index(){
        $this->listStu(0,10);

    }

    public function assignStu($userid){
        $User = M("User"); // 实例化User对象
        // 要修改的数据对象属性赋值
        $data['authority'] = 1;
        $map['userid'] = $userid;
        $User->where($map)->save($data); // 根据条件更新记录
        $this->index();



    }
    public function unAssignStu($userid){
        $User = M("User"); // 实例化User对象
        // 要修改的数据对象属性赋值
        $data['authority'] = 0;
        $map['userid'] = $userid;
        $User->where($map)->save($data); // 根据条件更新记录
        $this->index();
    }
    public function listStu($offset,$limitNum){
        $User = M("User");
        //查找status值为1的用户数据 以创建时间排序 返回10条数据
        $nums = $User->count();
        $list = $User->limit($offset.','.$limitNum)->select();
        $this->assign("stu_list",$list);
        $this->assign("stu_nums",$nums);
        $this->assign("offset",$offset);
        $this->assign("page_num",ceil($nums/$limitNum));
        if($offset>ceil($nums/$limitNum)){
            //错误页面
        }
        $this->display('Assign:assign');

    }
}
